package com.ymf.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Slf4j
@Service
public class FileService {
    @Value("${file.address}")
    private String rootfile;
    public String uploadAvatar(@RequestBody MultipartFile file){
        System.out.println(file.getOriginalFilename());
        try {
            file.transferTo(new File(rootfile+file.getOriginalFilename()));
        } catch (IOException e) {
            log.error("文件上传失败："+e);
        }
        return file.getOriginalFilename();
    }
}
